package com.atguigu.boot.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * XXXX 实体
 *
 * @author lihj
 * @version 1.0.0
 * @title CustomListenerServie
 * @description <TODO description class purpose>
 * @date 2023/7/11
 */
@Service
public class CustomListenerService {

    private Logger logger = LoggerFactory.getLogger(CustomListenerService.class);

    //上下文对象
    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发布消息
     * @Title: publish
     * @author OnlyMate
     * @Date 2018年9月14日 下午3:18:35
     * @param msg
     */
    public void publish(String msg) {
        //通过上下文对象发布监听
        logger.info("CustomListenerService 主动发布： ==> publish method : {}", msg);
        applicationContext.publishEvent(new CustomEvent(this,msg));
    }
}
